home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
byt86oct.arc
/
ALLOC.ARC
/
A1TEST.MOD
next >
Wrap
Text File
|
1985-07-12
|
4KB
|
185 lines
MODULE alloc1test;
FROM Alloc1 IMPORT blockPtr, allocate, free, setWord, getWord, blockSize,
getFreeList;
FROM MyTerminal IMPORT WriteString, Write, WriteLnString, WriteLn,
WriteCard, fatal, pause, ClearScreen, Read;
FROM SYSTEM IMPORT WORD, ADDRESS;
FROM InOut IMPORT ReadCard;
FROM MachineSpecific IMPORT writeAddress;
CONST maxIndex = 32767;
TYPE bPtr = POINTER TO block;
block = RECORD
size:CARDINAL;
CASE BOOLEAN OF
TRUE: nextBlock: bPtr;
| FALSE: contents:ARRAY[0..maxIndex] OF WORD;
END;
END;
VAR blockList:ARRAY['a'..'z'] OF blockPtr;
PROCEDURE rawPrintBlockHeader(blockp:bPtr);
BEGIN
WriteLnString("---------------------");
IF ADDRESS(blockp) = NIL THEN
WriteLnString("NIL");
ELSE
WriteString("Block (raw) ");
writeAddress(ADDRESS(blockp));
WriteString(" (");
WriteCard(blockp^.size, 0);
WriteLnString(" words)");
END;
END rawPrintBlockHeader;
PROCEDURE rawPrintBlock(blockp:bPtr);
VAR i:CARDINAL;
BEGIN
rawPrintBlockHeader(blockp);
IF blockp <> NIL THEN
WITH blockp^ DO
FOR i := 0 TO size-1 DO
WriteCard(i, 3); WriteString(': ');
WriteCard(CARDINAL(contents[i]), 0); WriteLn;
END;
END;
END;
END rawPrintBlock;
PROCEDURE printBlockHeader(blockp:blockPtr);
BEGIN
WriteLnString("---------------------");
IF ADDRESS(blockp) = NIL THEN
WriteLnString("NIL");
ELSE
WriteString("Block ");
writeAddress(ADDRESS(blockp));
WriteString(" (");
WriteCard(blockSize(blockp), 0);
WriteLnString(" words)");
END;
END printBlockHeader;
PROCEDURE printBlock(blockp:blockPtr);
VAR i:CARDINAL;
BEGIN
printBlockHeader(blockp);
IF ADDRESS(blockp) <> NIL THEN
FOR i := 0 TO blockSize(blockp)-1 DO
WriteCard(i, 3); WriteString(': ');
WriteCard(CARDINAL(getWord(blockp, i)), 0); WriteLn;
END;
END;
END printBlock;
PROCEDURE rawPrintFreeList;
VAR bp:bPtr;
BEGIN
bp := bPtr(getFreeList());
WHILE bp <> NIL DO
rawPrintBlockHeader(bp);
bp := bp^.nextBlock;
END;
WriteLnString("---------------------");
END rawPrintFreeList;
PROCEDURE printFreeList;
VAR bp:blockPtr;
bptr:bPtr;
BEGIN
bp := getFreeList();
WHILE ADDRESS(bp) <> NIL DO
printBlockHeader(bp);
bptr := bPtr(bp);
bp := blockPtr(bptr^.nextBlock);
END;
WriteLnString("---------------------");
END printFreeList;
PROCEDURE test;
VAR c1, c2:CHAR;
BEGIN
LOOP
Write('>');
Read(c1); Write(c1);
Read(c2); Write(c2);
CASE c1 OF
'a': doAlloc(c2);
| 'f': doFree(c2);
| 'r': IF letter(c2) THEN
rawPrintBlock(bPtr(blockList[c2]));
ELSE
rawPrintFreeList;
END;
| 'p': IF letter(c2) THEN
printBlock(blockList[c2]);
ELSE
printFreeList;
END;
| 's': doSet(c2);
| 'g': doGet(c2);
| 'q': EXIT;
ELSE
WriteLnString("a)lloc, f)ree, p)rint, r)aw print, qu)it, s)et, g)et");
END;
END;
END test;
PROCEDURE doAlloc(b:CHAR);
BEGIN
blockList[b] := allocate(getCard("Number of words: "));
END doAlloc;
PROCEDURE doFree(b:CHAR);
BEGIN
free(blockList[b]);
END doFree;
PROCEDURE doSet(b:CHAR);
BEGIN
setWord(blockList[b], getCard("Position: "), getCard("Value: "));
END doSet;
PROCEDURE doGet(b:CHAR);
BEGIN
WriteCard(CARDINAL(getWord(blockList[b], getCard("Position: "))), 0);
END doGet;
PROCEDURE getCard(s:ARRAY OF CHAR):CARDINAL;
VAR c:CARDINAL;
BEGIN
WriteString(s);
ReadCard(c);
WriteLn;
RETURN c;
END getCard;
PROCEDURE letter(c:CHAR):BOOLEAN;
BEGIN
RETURN (c >= 'a') AND (c <= 'z');
END letter;
PROCEDURE init;
VAR c:CHAR;
BEGIN
FOR c := 'a' TO 'z' DO
blockList[c] := blockPtr(NIL);
END;
END init;
BEGIN
ClearScreen;
init;
test;
END alloc1test.
z' DO
blockList[c] := blockPtr(NIL);
END;
END init;
BEGIN
ClearScreen;
ini